package p5;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-11-29
 * Time: 20:05
 */

/**
 * 全排列
 */
public class Main1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean []used = new boolean[n+1];
        ArrayList<Integer> list = new ArrayList<>();
        dfs(n, used, list);
    }

    private static void dfs(int n, boolean []used, ArrayList<Integer>list) {
        if(list.size() == n){
            list.forEach(val -> {
                System.out.print(val + " ");
            });
            System.out.println();
            return ;
        }

        for(int i=1;i<=n;i++){
            if(used[i]){
                continue;
            }
            list.add(i);
            used[i] = true;
            dfs(n,used,list);
            used[i] = false;
            list.remove(list.size()-1);
        }

    }
}
